package com.hzb.LNReader.reader;

import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;
import android.view.GestureDetector.SimpleOnGestureListener;

import com.hzb.LNReader.ReaderActivity;
import com.hzb.LNReader.util.ReaderPref;

public class GestureListener extends SimpleOnGestureListener {

	private ReaderView view;
	private int actEdgeY;
	private Window window;
	private ReaderActivity activity;
	private boolean isFullScreen;
	
	public GestureListener(ReaderView view) {
		this.isFullScreen = ReaderPref.isFullScreen();
		this.view = view;
		this.actEdgeY = (view.getScreenHeight() >> 1);
		this.window = ((ReaderActivity)view.getContext()).getWindow();
		this.activity = (ReaderActivity) view.getContext();
	}
	
	@Override
	public boolean onDoubleTap(MotionEvent e) {
		isFullScreen = !isFullScreen;
		ReaderPref.setFullScreen(isFullScreen);
		if (isFullScreen) {
			window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
			view.scrollBy(0, -activity.getStatusBarHeight());
		} else {
			window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
			view.scrollBy(0, activity.getStatusBarHeight());					
		}
		return true;
	}

	@Override
	public boolean onSingleTapConfirmed(MotionEvent e) {
		if (e.getRawY() > actEdgeY) {
			view.scrollNextPage();
		} else {
			view.scrollPrevPage();
		}
		return true;
	}

}
